﻿using System.Collections.Generic;

namespace Borg.Framework
{
    public abstract class PlugStartup<T> : FrameworkStartup<FrameworkPlugAttribute>
        where T : FrameworkPlugAttribute
    {
        public override void ExtensionCreated(object s, ExtensionEventArgs args)
        {
            IList<T> customAttributes =
                AssemblyAnalyzer.GetCustomAttributes<T>(args.ExtensionTypeInfo.Type);

            foreach (var local in customAttributes)
                PlugCreated(args.ExtensionInfo.PlugInfos[local.Name], local);
        }

        public override void ExtensionReleased(object s, ExtensionEventArgs args)
        {
            IList<T> customAttributes =
                AssemblyAnalyzer.GetCustomAttributes<T>(args.ExtensionTypeInfo.Type);

            foreach (var local in customAttributes)
                PlugReleased(args.ExtensionInfo.PlugInfos[local.Name], local);
        }

        public abstract void PlugCreated(PlugInfo plug, T attr);
        public abstract void PlugReleased(PlugInfo plug, T attr);
    }
}

